<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
  <myHead th:replace="basic/layout :: head('用户管理')"></myHead>
  <!-- Bootstrap 5 -->
</head>
<body>
<div th:replace="basic/layout :: topNav('back')"></div>
<div class="row">
  <div th:replace="basic/layout :: menu"></div>
  
  <div class="col-10">
    <div class="container mt-4">
      <!-- 标题与操作按钮 -->
      <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>用户管理</h2>
        <!-- 新增按钮（仅user:add权限可见） -->
        <a th:href="@{/users/add}" class="btn btn-primary"
           sec:authorize="hasAuthority('user:add')">
          <i class="bi bi-plus-circle"></i> 新增用户
        </a>
      </div>
      
      <!-- 消息提示 -->
      <div th:if="${msg}" class="alert alert-success alert-dismissible fade show">
        <span th:text="${msg}"></span>
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
      </div>
      <div th:if="${error}" class="alert alert-danger alert-dismissible fade show">
        <span th:text="${error}"></span>
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
      </div>
      
      <!-- 用户表格 -->
      <div class="card shadow-sm">
        <div class="card-body">
          <table class="table table-hover">
            <thead class="table-light">
            <tr>
              <th>ID</th>
              <th>用户名</th>
              <th>昵称</th>
              <th>邮箱</th>
              <th>手机号</th>
              <th>状态</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="user : ${users}">
              <td th:text="${user.id}"></td>
              <td th:text="${user.username}"></td>
              <td th:text="${user.nickname}"></td>
              <td th:text="${user.email} ?: '-'"></td>
              <td th:text="${user.phone} ?: '-'"></td>
              <td>
                <span class="badge bg-success" th:if="${user.status == 1}">正常</span>
                <span class="badge bg-danger" th:if="${user.status == 0}">禁用</span>
              </td>
              <td th:text="${#temporals.format(user.createTime, 'yyyy-MM-dd HH:mm')}"></td>
              <td>
                <!-- 编辑按钮（仅user:edit权限可见） -->
                <a th:href="@{/users/edit/{id}(id=${user.id})}"
                   class="btn btn-sm btn-outline-primary me-2"
                   sec:authorize="hasAuthority('user:edit')">
                  编辑
                </a>
                <!-- 删除按钮（仅user:delete权限可见） -->
                <a th:href="@{/users/delete/{id}(id=${user.id})}"
                   class="btn btn-sm btn-outline-danger"
                   sec:authorize="hasAuthority('user:delete')"
                   onclick="return confirm('确定删除该用户吗？')">
                  删除
                </a>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>